<?php

/* @var $this \yii\web\View */
/* @var $content string */

use backend\assets\AppAsset;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use common\widgets\Alert;

AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php $this->registerCsrfMetaTags() ?>
    <title><?= Html::encode($this->title) . ' - ' . Yii::$app->name?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>

<div class="wrap">
    <?php
    NavBar::begin([
        'brandLabel' => Yii::$app->name,
        'brandUrl' => Yii::$app->homeUrl,
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',
        ],
    ]);
    
    if (Yii::$app->user->isGuest) {
        $menuItems = [
            ['label' => '首页', 'url' => ['/site/index']],
            ['label' => '登录', 'url' => ['/site/login']]
        ];
    } else {

        if(Yii::$app->user->identity->limitStr == '' || Yii::$app->user->identity->limitStr == 'init' || Yii::$app->user->identity->limitStr == 'manager'){
            $menuItems = [
                ['label' => '首页', 'url' => ['/site/index']],
                ['label' => '排队', 'items' => [
                        ['label' => '列表排队', 'url' => ['/queues/queue-list?find=all']],
                        ['label' => '排队统计', 'url' => ['/queues/stat']],
                    ]
                ],
                ['label' => '会员', 'url' => ['/members/index']],
                ['label' => '员工', 'url' => ['/users/index']],
                ['label' => '设置', 'url' => ['/setting/index']],
                ['label' => '<i class="fa fa-user"></i> '.Yii::$app->user->identity->username, 'items' => [
                        ['label' => '修改密码', 'url' => ['/site/editpwd']],
                        [
                            'label' => Html::beginForm(['/site/logout'], 'post'). Html::submitButton('退出', ['class' => 'logout']) . Html::endForm(), 
                            'type' => 'html'
                        ],
                    ]
                ]
            ];
        }else{
            $menuItems = [
                ['label' => '首页', 'url' => ['/site/index']],
                ['label' => '<i class="fa fa-user"></i> '.Yii::$app->user->identity->username, 'items' => [
                        ['label' => '修改密码', 'url' => ['/site/editpwd']],
                        [
                            'label' => Html::beginForm(['/site/logout'], 'post'). Html::submitButton('退出', ['class' => 'logout']) . Html::endForm(), 
                            'type' => 'html'
                        ],
                    ]
                ]
            ];
        }

//        $menuItems[] = '<li>'
//            . Html::beginForm(['/site/logout'], 'post')
//            . Html::submitButton(
//                '<i class="fa fa-user"></i> 退出',
//                ['class' => 'btn btn-link logout']
//            )
//            . Html::endForm()
//            . '</li>';
    }
    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
        'items' => $menuItems,
        'encodeLabels' => false
    ]);
    NavBar::end();
    ?>

    <div class="container-fluid">
        <?= Breadcrumbs::widget([
            'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
        ]) ?>
        <?= Alert::widget() ?>
        <?= $content ?>
    </div>
</div>

<footer class="footer">
    <div class="container">
        <p class="pull-left">&copy; <?= Html::encode(Yii::$app->name) ?> <?= date('Y') ?></p>
        <p class="pull-right"><?= Yii::powered() ?></p>
    </div>
</footer>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
